﻿Imports System.Windows.Forms

Public Class ServerMessageDialog

    Dim MIcon As System.Drawing.Image

    Public Property Message As MPQService.ServerMessage

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        If MIcon Is Nothing Then
            MsgBox("Please select an icon")
            Exit Sub
        End If
        If Message Is Nothing Then
            Message = New MPQService.ServerMessage
        End If
        Message.Title = TitleBox.Text
        Message.Icon = MIcon
        Message.Message = MessageBox.Text
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub ServerMessageDialog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For Each Icon As Reflection.PropertyInfo In GetType(System.Drawing.SystemIcons).GetProperties()
            IconListBox.Items.Add(Icon.Name)
        Next
        If Message Is Nothing Then
            DeleteButton.Enabled = False
            IconListBox.SelectedIndex = 0
        Else
            TitleBox.Text = Message.Title
            MessageBox.Text = Message.Message
            MIcon = Message.Icon
            IconBox.Image = MIcon
            IconListBox.SelectedIndex = -1
        End If
    End Sub

    Private Sub IconListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IconListBox.SelectedIndexChanged
        MIcon = GetType(System.Drawing.SystemIcons).GetProperty(IconListBox.SelectedItem).GetValue(Nothing, Nothing).ToBitmap
        IconBox.Image = MIcon
    End Sub

    Private Sub DeleteButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteButton.Click
        GameServer.ServerMessages.Remove(Message)
        Me.Close()
    End Sub
End Class
